/**
 * projectName: mbzwb-parent
 * fileName: ResultTypeEnum.java
 * packageName: com.palmdoctor.mb.base.rule.constant
 * date: 2021-09-24 10:52
 * copyright(c) 2021 http://www.hydee.cn/ Inc. All rights reserved.
 */
package com.zny.sescore.rule.constant;


import com.zny.sescore.model.CodeName;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @version: V1.0
 * @author: zhangnayi
 * @className: ResultTypeEnum
 * @packageName: com.palmdoctor.mb.base.rule.constant
 * @description: 结果计算规则枚举
 * @data: 2021-09-24 10:52
 **/
@RuleConstant(value = "result_type", name = "结果计算规则")
public enum ResultTypeEnum implements IRuleConstant {
    SUM("sum", "直接求和"),
    EXP_TEXT("exp_text", "公式求和"),
    MATCH_EXP("match_exp", "匹配规则"),
    ;

    private String code;

    private String name;

    ResultTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public List<CodeName> codeNames() {
        return Stream.of(values())
                .map(v -> new CodeName(v.code, v.name))
                .collect(Collectors.toList());
    }

    public static ResultTypeEnum getByCode(String code) {
        if (code == null) {
            return null;
        }
        for (ResultTypeEnum typeEnum : values()) {
            if (Objects.equals(typeEnum.code, code)) {
                return typeEnum;
            }
        }
        return null;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }
}